//
//  VideoTableViewCell.m
//  A Learning Walk
//
//  Created by dllo on 16/6/18.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "VideoTableViewCell.h"
//#import <AVFoundation/AVFoundation.h>

@interface VideoTableViewCell ()
@property(nonatomic, retain)UIVisualEffectView *effect;//磨玻璃

//@property(nonatomic, retain)AVPlayer *videoPlayer;
//@property(nonatomic, retain)AVPlayerLayer *layer1;
//@property(nonatomic, retain)UIView *myView;

@end

@implementation VideoTableViewCell

-(void)dealloc{
    [_imageV release];
    [_labelT release];
    [_buttonP release];
    [_imageP release];
    [_model release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}
-(void)creatCell{

    self.imageV = [[UIImageView alloc] init];
    self.imageV.backgroundColor = [UIColor whiteColor];
    self.imageV.userInteractionEnabled = YES;
    [self.contentView addSubview:self.imageV];
    
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//    [self.imageV addGestureRecognizer:tap];
    
    self.labelT = [FengLabel LabelwithFrame:CGRectMake(0, 0, 0, 0) Color:[UIColor clearColor] font:17];
    [self.contentView addSubview:self.labelT];
    self.labelT.textColor = [UIColor whiteColor];
    
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    self.effect = [[UIVisualEffectView alloc] initWithEffect:blur];
    [self.labelT addSubview:self.effect];
    
    self.imageP = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"122"]];
    self.imageP.backgroundColor = [UIColor clearColor];
    [self.imageV addSubview:self.imageP];
    
    
    
    [self.imageV release];
    [self.labelT release];
    
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.imageV.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height-10);
    
    self.effect.frame = self.labelT.bounds;
    
    self.labelT.frame = CGRectMake(0, self.imageV.frame.size.height-30, self.contentView.frame.size.width, 30);
    self.imageP.frame = CGRectMake((self.imageV.frame.size.width-50)/2, 50, 50, 50);
    
}

-(void)setModel:(videoModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:_model.cover]];
    self.labelT.text = [NSString stringWithFormat:@"   %@",_model.title];
}
//-(void)tapAction:(UITapGestureRecognizer *)noti{
//    self.imageV.frame = CGRectMake(0, 0, 0, 0);
//    self.imageP.frame= CGRectMake(0, 0, 0, 0);
//    
//    NSURL *url = [NSURL URLWithString:_model.mp4_url];
//    //构造AVPlayerItem对象
//    AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:url];
//    //初始化player
//    self.videoPlayer = [[AVPlayer alloc] initWithPlayerItem:item];
//    //到这里还没有画面,我们还需要一个AVPlayerLayer对象
//    AVPlayerLayer *layer1 = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];
//    self.layer.frame = CGRectMake(0, 100, self.contentView.frame.size.width, self.contentView.frame.size.height-10);
//    layer1.videoGravity = AVLayerVideoGravityResizeAspect;//让其居中显示
//    //添加到屏幕上显示
//    [self.contentView.layer addSublayer:self.layer];
//    
//    self.myView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.contentView.frame.size.width, self.contentView.frame.size.height-10)];
//    
//    [self.contentView addSubview:self.myView];
//}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
